package Day28;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Demo04 {
    public static void main(String[] args) throws Exception {
        //加载类
        Class c1 = Class.forName("Day28.Person");
        //获取类的构造方法
        Constructor c = c1.getConstructor();
        //创建对象
        Object o = c.newInstance();
        //获取类的方法
        Method setName = c1.getMethod("setName", String.class);
        Method setAge = c1.getDeclaredMethod("setAge", int.class);
        setAge.setAccessible(true);
        //参数1.哪个对象要执行setName方法
        //参数2.调用方法时传递的参数 0-n
        setName.invoke(o,"lisi");
        setAge.invoke(o,18);
        System.out.println(o);


    }
}
